package com.hqd.jjvm.classformat.constantpool;

/**
 * 常量池类型
 *
 * @author hqd
 */

public enum ConstantInfoType {
    CONSTANT_UTF8(1),
    CONSTANT_INTEGER(3),
    CONSTANT_FLOAT(4),
    CONSTANT_LONG(5),
    CONSTANT_DOUBLE(6),
    CONSTANT_CLASS(7),
    CONSTANT_STRING(8),
    CONSTANT_FIELDREF(9),
    CONSTANT_METHODREF(10),
    CONSTANT_INTERFACEMETHODREF(11),
    CONSTANT_NAMEANDTYPE(12),
    CONSTANT_METHODHANDLE(15),
    CONSTANT_METHODTYPE(16),
    CONSTANT_INVOKEDYNAMIC(18);

    private int tag;

    ConstantInfoType(int tag) {
        this.tag = tag;
    }

    public int getTag() {
        return tag;
    }

    public static ConstantInfoType getType(Integer tag) {
        if (tag == null) {
            return null;
        }
        ConstantInfoType[] types = ConstantInfoType.values();
        for (ConstantInfoType type : types) {
            if (type.tag == tag) {
                return type;
            }
        }
        return null;
    }
}
